package com.yiyuan.app.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.guaike.core.mybatis.plugins.BaseDAO;
import com.yiyuan.app.entity.po.MRankBattlePushCoinsPO;
import com.yiyuan.app.mapper.MRankBattlePushCoinsMapper;
import org.springframework.stereotype.Repository;

import java.time.LocalDate;
import java.util.List;

@Repository
public class MRankBattlePushCoinsDAO extends BaseDAO<MRankBattlePushCoinsMapper, MRankBattlePushCoinsPO> {


    public List<MRankBattlePushCoinsPO> findBattleRankList() {
        LambdaQueryWrapper<MRankBattlePushCoinsPO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(MRankBattlePushCoinsPO::getIsRank, Boolean.TRUE);
        queryWrapper.eq(MRankBattlePushCoinsPO::getRankDate, LocalDate.now().minusDays(1));
        queryWrapper.orderByAsc(MRankBattlePushCoinsPO::getRankNo);
        return getBaseMapper().selectList(queryWrapper);
    }

    public MRankBattlePushCoinsPO findUserToday(LocalDate today, Long userId) {
        LambdaQueryWrapper<MRankBattlePushCoinsPO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(MRankBattlePushCoinsPO::getUserId, userId);
        queryWrapper.eq(MRankBattlePushCoinsPO::getRankDate, today);
        return getBaseMapper().selectOne(queryWrapper);
    }
}
